//
//  PrivateMessage.m
//  Coding_My
//
//  Created by showXxie on 2017/8/23.
//  Copyright © 2017年 sooxie. All rights reserved.
//

#import "PrivateMessage.h"

@implementation PrivateMessage

//字典中嵌套字典
+(NSDictionary *)mj_objectClassInArray {
    
    return @{
             @"sender":@"User",
             @"friend":@"User"
             };
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        _sendStatus = PrivateMessageStatusSendSucess;
        _id = @(-1);
    }
    return self;
}

#pragma mark - 解析xml
- (void)setContent:(NSString *)content {
    if (_content != content) {
        _htmlMedia = [HtmlMedia htmlMediaWithString:content showType:MediaShowTypeCode];
        if (_htmlMedia.contentDisplay.length <= 0 && _htmlMedia.imageItems.count <= 0 && !_nextImg) {
            
            _content = @"    ";//占位 没图片和文字时
        }else{
            _content = _htmlMedia.contentDisplay;
        }
    }
}

//判断是否有图片 xml遍历时会得到是否有图片
- (BOOL)hasMedia{
    
    return self.nextImg || (self.htmlMedia && self.htmlMedia.imageItems.count> 0);
}


//是否是语音
- (BOOL)isVoice{
    return (_type.integerValue == 1 || _voiceMedia);
}

//是不是猴子的表情
- (BOOL)isSingleBigMonkey{
   
    BOOL isSingleBigMonkey = NO;
 
    if (self.content.length == 0) {
        if (_htmlMedia.imageItems.count == 1) {
          
            HtmlMediaItem *item = [_htmlMedia.imageItems firstObject];
            if (item.type == HtmlMediaItemType_EmotionMonkey) {
                isSingleBigMonkey = YES;
            }
            
        }
    }
    
    return isSingleBigMonkey;
    
}




+ (instancetype)privateMessageWithObj:(id)obj andFriend:(User *)curFriend{
    
    PrivateMessage *nextMsg = [[PrivateMessage alloc] init];

    
    return nextMsg;
}


@end
